package com.young.common.expression.dns;

import java.net.InetAddress;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * @description：
 * @author: yangyahui01
 * @date: 11/29/24 12:37 PM
 */
public interface NamingResolver {
    String RESOLVER_DOMAIN_PREFIX = "domain.";
    String RESOLVER_SERVICE_PREFIX = "service.";
    Pattern IP_ADDRESS_PATTERN = Pattern.compile("^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$");

    InetAddress[] resolve(String domain);

    InetAddress[] domainResolve(String domain);

    default String findService(String service) {
        return null;
    }

    InetAddress[] serviceResolve(String service);

    Map<String, String> copyDomainResolvers();

    Map<String, String> copyServiceResolvers();

    Map<String, String> copyServiceGroupResolvers();

    static boolean isDomain(String target) {
        return target.contains(".");
    }

    static boolean isService(String target) {
        return !target.contains(".");
    }

    static boolean isIpAddress(String target) {
        return IP_ADDRESS_PATTERN.matcher(target).matches();
    }
}
